/*
 * @Author: chen haoxuan
 * @Date: 2021-06-05 22:22:17
 * @LastEditTime: 2021-06-05 22:38:38
 */
// 5.5.3 多层派生时的构造函数
#include<iostream>
#include<string>
using namespace std;
class Student
{
  public:
    Student(int n,string nam)
    {
      num=n;
      name=nam;
    }
    void display()
    {
      cout<<"num: "<<num<<endl;
      cout<<"name: "<<name<<endl; 
    }
  protected:
    int num;
    string name;
};
class Student1:public Student
{
  public:
    Student1(int n,char nam[10],int a):Student(n,nam)
    {
      age=a;
    }
    void show()
    {
      display();
      cout<<"age: "<<age<<endl;
    }
  private:
    int age; 
};
class Studnet2:public Student1
{
  public:
    Studnet2(int n,char nam[10],int a,int s):Student1(n,nam,a)
    {
      score=s;
    }
    void show_all()
    {
      show();
      cout<<"score: "<<score<<endl;
    }
  private:
    int score;
};
int main()
{
  Studnet2 stud(10010,"wang-li",19,99);
  stud.show_all();
  system("pause");
  return 0;
}
/*
    不要列出每一层派生类的构造函数，只须写出其上一层的派生类(即它的直接基类)对应的构造函数
    (1) 先初始化基类的数据成员
    (2) 再初始化Student1的数据成员
    (3) 最后初始化Student2的数据成员对象
*/